<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Comment;

class CommentController extends Controller
{
    //
    public function index(){
        $comment = Comment::all();
        return view('admin/comment/index')->with('comments', $comment);
    }

    public function edit($id){
        $comment = Comment::find($id);
        return view('admin/comment/edit')->with('comment', $comment); 
    }
    
    public function update(Request $request){
        $comment = Comment::find($request->get('id'));
        $comment->content = $request->get('content');

        if ($comment->save()) {
            return redirect('admin/comment');
        } else {
            return redirect()->back()->withInput()->withErrors('编辑评论失败！');
        }
    }

    public function destroy($id){
        $comment = Comment::find($id);
        if($comment->delete()){
            return redirect('admin/comment');
        }else{
            return redirect('admin/comment')->back()->withInput()->withErrors('删除评论失败！');
        }
    }

}
